/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bank.centraal;

import bank.client.BankierApplicatie;
import java.io.FileOutputStream;
import java.rmi.*;
import java.util.Properties;
import javax.swing.JFrame;

/**
 *
 * @author Tobias
 */
public class CentraalServer extends JFrame  {

    private String name;
    private ICentraal centraal;
    private BankierApplicatie bank;

    public CentraalServer(String name){
        try {
            this.name=name;

            String address = java.net.InetAddress.getLocalHost()
                            .getHostAddress();
            int port = 1099;

            Properties props = new Properties();
            String rmiCentraal = address + ":" + port + "/" + name;
            props.setProperty("centraal", rmiCentraal);

            FileOutputStream out = new FileOutputStream(name+".props");
            props.store(out, null);
            out.close();

//            if (java.rmi.registry.LocateRegistry.getRegistry()==null)
//                            java.rmi.registry.LocateRegistry.createRegistry(port);
            centraal = new Centraal();
            Naming.rebind(name, centraal);
            System.out.println("counter of Centraal bound as " + name);

            init();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }

    private void init() throws Exception {
        setSize(250, 0);
        setTitle(name+"balie is geopend");
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String naam = "centraal";
		new CentraalServer(naam);
    }

}
